#ifndef __PROTOBUFFIK_ENDIANNESS_H_
#define __PROTOBUFFIK_ENDIANNESS_H_

#include "protobuffik_types.h"


namespace protobuffik
{

enum endianness
{
	PROTOBUFFIK_BIG_ENDIAN,
	PROTOBUFFIK_LITTLE_ENDIAN
};


inline
endianness get_current_endianness( )
{
	static bool isInited = false;
	static endianness curEndianness = PROTOBUFFIK_LITTLE_ENDIAN;

	if( !isInited )
	{
		union
		{
			struct
			{
				char c1;
				char c2;
			};

			short s;
		} test;

		test.c1 = 1;
		test.c2 = 0;
		if( test.s == 1 )
			curEndianness = PROTOBUFFIK_LITTLE_ENDIAN;
		else
			curEndianness = PROTOBUFFIK_BIG_ENDIAN;
		isInited = true;
	}

	return curEndianness;
}


};

#endif